package com.scale.service.voice.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * 进度更新消息数据
 * @author crp
 * @since 2025-09-28
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProgressUpdateData {
    
    /**
     * 任务状态
     */
    private String status;         // PENDING, PROCESSING, COMPLETED, FAILED
    
    /**
     * 进度百分比
     */
    private Integer progress;      // 0-100
    
    /**
     * 当前步骤
     */
    private String currentStep;    // ASR, AI_DIALOGUE, TTS, STORAGE
    
    /**
     * 状态描述
     */
    private String message;
    
    /**
     * 识别文本
     */
    private String recognizedText;
    
    /**
     * AI回复
     */
    private String aiReply;
    
    /**
     * AI语音URL
     */
    private String voiceUrl;
    
    /**
     * 用户语音URL
     */
    private String userVoiceUrl;
    
    /**
     * 会话ID
     */
    private Long conversationId;
    
    /**
     * 错误代码
     */
    private String errorCode;
    
    /**
     * 错误消息
     */
    private String errorMessage;
    
    /**
     * 时间戳
     */
    private String timestamp;
    
    public ProgressUpdateData() {
        this.timestamp = LocalDateTime.now().toString();
    }
    
    /**
     * 创建进度更新数据
     */
    public static ProgressUpdateData create(String status, Integer progress, String currentStep, String message) {
        ProgressUpdateData data = new ProgressUpdateData();
        data.setStatus(status);
        data.setProgress(progress);
        data.setCurrentStep(currentStep);
        data.setMessage(message);
        return data;
    }
    
    /**
     * 创建任务完成数据
     */
    public static ProgressUpdateData completed(String recognizedText, String aiReply, String voiceUrl, String userVoiceUrl, Long conversationId) {
        ProgressUpdateData data = new ProgressUpdateData();
        data.setStatus("COMPLETED");
        data.setProgress(100);
        data.setCurrentStep("STORAGE");
        data.setMessage("处理完成！");
        data.setRecognizedText(recognizedText);
        data.setAiReply(aiReply);
        data.setVoiceUrl(voiceUrl);
        data.setUserVoiceUrl(userVoiceUrl);
        data.setConversationId(conversationId);
        return data;
    }
    
    /**
     * 创建任务失败数据
     */
    public static ProgressUpdateData failed(String errorCode, String errorMessage) {
        ProgressUpdateData data = new ProgressUpdateData();
        data.setStatus("FAILED");
        data.setProgress(0);
        data.setCurrentStep("ERROR");
        data.setMessage("处理失败");
        data.setErrorCode(errorCode);
        data.setErrorMessage(errorMessage);
        return data;
    }
}
